﻿using IntelligentAgriculture.Contracts.Interface.EliminationModelService;
using IntelligentAgriculture.Domain.Entity;
using IntelligentAgriculture.WebAPI.Application.Command.DeathModelCommand;
using IntelligentAgriculture.WebAPI.Application.Command.EliminationModelCommand;
using MediatR;

namespace IntelligentAgriculture.WebAPI.Application.CommandHandler.EliminationModelCommandHandler
{
    public class EliminationUpdateCommandHandler : IRequestHandler<EliminationUpdateCommand, Results<int>>
    {
        private readonly IEliminationModelService _IeliminationModelService;
        public EliminationUpdateCommandHandler(IEliminationModelService ieliminationModelService)
        {
            _IeliminationModelService = ieliminationModelService;
        }
        /// <summary>
        /// 处理淘汰列表的更新操作。
        /// </summary>
        /// <param name="request">更新请求参数</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>修改结果</returns>
        public async Task<Results<int>> Handle(EliminationUpdateCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var entity = new Eliminationmodel()
                {
                    SheepRescissionSex = request.SheepRescissionSex,
                    Siwang = request.Siwang,
                    DepartureState = request.DepartureState,
                    ReproductiveState = request.ReproductiveState,
                    BirthDate = request.BirthDate,
                    BuildingManagementId = request.BuildingManagementId,
                    ColumnManagementId = request.ColumnManagementId,
                    CreateBy = request.CreateBy,
                    CreateDate = request.CreateDate,
                    EarTag = request.EarTag,
                    EliminationId = request.EliminationId,
                    LogicalDeletion = request.LogicalDeletion,
                    PhaseOutDate = request.PhaseOutDate,
                    TreatmentMeasure = request.TreatmentMeasure,
                    UpdateBy = request.UpdateBy,
                    UpdateDate = request.UpdateDate,
                    Variety = request.Variety,
                };

                var list = await _IeliminationModelService.UpateEartag(entity);
                return Results<int>.DataResult(list);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
